package org.azj.ImageEditor;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public abstract class ImagePreparer {
	// 如果成功，返回新文件名，如果失败则返回空字符串。
	// 参数必须是全路径或者全名
	abstract public String prepare(String targetFolder, String filePath) throws Exception;
	
	protected void copy(String srcPath, String targetPath) throws Exception {
		BufferedInputStream bis = null;
		BufferedOutputStream bos = null;
		try {
			bis = new BufferedInputStream(new FileInputStream(srcPath));
	        bos = new BufferedOutputStream(new FileOutputStream(targetPath));
	        byte[] temp = new byte[1024];
	        while(bis.read(temp) != -1){
	        	bos.write(temp);
	        }
		} catch (Exception e) {
			String msg = 
					String.format(
							"复制文件时出现错误[%s -> %s], 错误信息是[%s]", 
							srcPath, targetPath, e.getMessage());
			throw new Exception(msg);
		} finally {
			bos.close();
	        bis.close();
		}
		
        
	}
	
}
